import logging

from fastapi import APIRouter, Depends

from like.schema_base import PageInationResult
from like.http_base import unified_resp
from .schemas import (
    MedicalIcd10InsuranceMappingListIn, MedicalIcd10InsuranceMappingExportIn, MedicalIcd10InsuranceMappingDetailIn, MedicalIcd10InsuranceMappingAddIn, 
    MedicalIcd10InsuranceMappingEditIn, MedicalIcd10InsuranceMappingDelIn, MedicalIcd10InsuranceMappingOut)
from .service import IMedicalIcd10InsuranceMappingService, MedicalIcd10InsuranceMappingService

logger = logging.getLogger(__name__)

router = APIRouter(prefix='/mapping')


@router.get('/list', response_model=PageInationResult[MedicalIcd10InsuranceMappingOut])
@unified_resp
async def mapping_list(
        list_in: MedicalIcd10InsuranceMappingListIn = Depends(),
        medical_icd10_insurance_mapping_service: IMedicalIcd10InsuranceMappingService = Depends(MedicalIcd10InsuranceMappingService.instance)):
    """存储ICD10国临版2.0与医保版2.0对照信息的列表"""
    result = await medical_icd10_insurance_mapping_service.list(list_in)
    # result.file_name = "存储ICD10国临版2.0与医保版2.0对照信息的"
    return result

@router.get('/export', response_model=bytes)
@unified_resp
async def mapping_export(export_in: MedicalIcd10InsuranceMappingExportIn = Depends(), MedicalIcd10InsuranceMapping_service: IMedicalIcd10InsuranceMappingService = Depends(MedicalIcd10InsuranceMappingService.instance)):
    return await MedicalIcd10InsuranceMapping_service.export_excel(export_in)


@router.get('/detail')
@unified_resp
async def mapping_detail(
        detail_in: MedicalIcd10InsuranceMappingDetailIn = Depends(),
        medical_icd10_insurance_mapping_service: IMedicalIcd10InsuranceMappingService = Depends(MedicalIcd10InsuranceMappingService.instance)):
    """存储ICD10国临版2.0与医保版2.0对照信息的详情"""
    return await medical_icd10_insurance_mapping_service.detail(detail_in.id)


@router.post('/add')
@unified_resp
async def mapping_add(
        add_in: MedicalIcd10InsuranceMappingAddIn,
        medical_icd10_insurance_mapping_service: IMedicalIcd10InsuranceMappingService = Depends(MedicalIcd10InsuranceMappingService.instance)):
    """存储ICD10国临版2.0与医保版2.0对照信息的新增"""
    return await medical_icd10_insurance_mapping_service.add(add_in)


@router.post('/edit')
@unified_resp
async def mapping_edit(
        edit_in: MedicalIcd10InsuranceMappingEditIn,
        medical_icd10_insurance_mapping_service: IMedicalIcd10InsuranceMappingService = Depends(MedicalIcd10InsuranceMappingService.instance)):
    """存储ICD10国临版2.0与医保版2.0对照信息的编辑"""
    return await medical_icd10_insurance_mapping_service.edit(edit_in)


@router.post('/del')
@unified_resp
async def mapping_del(
        del_in: MedicalIcd10InsuranceMappingDelIn,
        medical_icd10_insurance_mapping_service: IMedicalIcd10InsuranceMappingService = Depends(MedicalIcd10InsuranceMappingService.instance)):
    """存储ICD10国临版2.0与医保版2.0对照信息的删除"""
    return await medical_icd10_insurance_mapping_service.delete(del_in.id)
